﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Fluid.Controls;
using System.Drawing;
using TouchRC.Custom_Controls.Events;
using TouchRC.Logic;

namespace TouchRC.Custom_Controls
{
    public class AdjustablePanel : FluidPanel
    {
        private AdjustableLabel m_Label;
        private int m_BaseHeight = 0;
        private int m_MaxHeight = AppSettings.ScreenResolution.Height;
        private int m_MinHeight = 0;

        protected override void InitControl()
        {
            base.InitControl();

            BackColor = Color.Black;
            ForeColor = Color.White;
            GradientFill = true;
            GradientFillOffset = 24;
            EnableDoubleBuffer = true;
            Alpha = 175;

            
            m_Label = new AdjustableLabel();
            int width = m_Label.ScaleX(AppSettings.ScreenResolution.Width);
            m_Label.Bounds = new Rectangle(0, 5, width, 0);
            m_Label.Visible = true;
            m_Label.HeightChanged += new EventHandler<HeightChangedEventArgs>(m_Label_HeightChanged);
            m_Label.ForeColor = Color.White;

            Controls.Add(m_Label);
        }

        public event EventHandler HeightChanged;

        private void m_Label_HeightChanged(object sender, HeightChangedEventArgs e)
        {
            int newHeight = UnscaleY(e.NewHeight) + m_BaseHeight;
            if (newHeight > m_MaxHeight)
                newHeight = m_MaxHeight;
            else if (newHeight < m_MinHeight)
                newHeight = m_MinHeight;

            this.Height = ScaleY(newHeight);

            if (HeightChanged != null) HeightChanged(sender, e);
        }

        public int MaxHeight
        {
            get { return m_MaxHeight; }
            set { m_MaxHeight = value; }
        }

        public int MinHeight
        {
            get { return m_MinHeight; }
            set { m_MinHeight = value; }
        }

        public new Rectangle Bounds
        {
            set
            {
                base.Bounds = value;
                m_Label.Bounds = value;
            }
        }

        public new Font Font
        {
            get { return m_Label.Font; }
            set { m_Label.Font = value; }
        }

        public string Text
        {
            get { return m_Label.Text; }
            set { m_Label.Text = value; }
        }

        public int BaseHeight
        {
            get { return m_BaseHeight; }
            set { m_BaseHeight = value; }
        }

        public StringAlignment LineAlignment
        {
            get { return m_Label.LineAlignment; }
            set { m_Label.LineAlignment = value; }
        }

        public StringAlignment Alignment
        {
            get { return m_Label.Alignment; }
            set { m_Label.Alignment = value; }
        }

        public void ShowAdjustablePanel()
        {
            Show(ShowTransition.FromBottom);
        }

        public void HideAdjustablePanel()
        {
            Close(ShowTransition.FromBottom);
        }

        public void ReadjustHeight()
        {
            m_Label.ReadjustHeight();
        }
    }
}
